<?php
namespace App\Http\Controllers\User;

use App\Models\AchievementCost;
use App\Models\AchievementCostDetail;
use App\Models\AchievementCostStandard;
use App\Models\AttendanceSet;
use App\Models\Company;
use App\Models\CorpInfo;
use App\Models\Feedback;
use App\Models\FeedbackDetail;
use App\Models\FeedbackSetDetail;
use App\Models\Group;
use App\Models\RewardPunishSet;
use App\Models\RewardPunishSetDetail;
use App\Models\User;
use App\Models\UserPerformance;
use App\Models\UserPerformanceMonth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\User\UserBaseController;
use App\Models\Keys;
use Curl\Curl;
use App\Models\RoleUser;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use DB;
use App\Models\Achievement;
use App\Models\Attendance;
use App\Models\RewardPunishDetail;
use  App\Models\Tips;


class PerformanceController extends UserBaseController
{

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    public function __construct()
    {
        parent::__construct();
    }

    
    
    //历史考评
    public function getHistoryPerf(Request $request)
    {
        $uid = $request->input('uid', 0);
        if ($uid <= 0) {
            $uid = $this->user->id;
        }
        $user_logo = User::find($uid);
        $year_param = $request->input('year', 0);
        $company = Company::where('id',$this->corpid)->first();
        if(!is_positive_int($year_param)){
            $year_param = getCurrentYear();
        }
        if(!in_array($year_param,explode(',',$company->years_array))){
            $year_param = $company->from_year;
        }

        $years = explode(',',$company->years_array);
        rsort($years);
        $now = date('Y') + 10;
        $yearlist = array();
        foreach($years as $y){
            $yearlist[] = array(
                'id'=>$y,
                'value'=>$y.'年',
            );
        }
        $yearlist = json_encode($yearlist);

        $perf = UserPerformance::where('user_id',$uid)->where('corpid',$this->corpid)->where('year_param',$year_param)->first();
        if(empty($perf)){
            $perf = new UserPerformance();
            $perf->corpid = $this->corpid;
            $perf->year_param = $year_param;
            $perf->user_id = $uid;
            $perf->save();
        }

        $standard_t = Achievement::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('standard');
        $score_t = Achievement::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('score');
        if($standard_t == 0){
            $avg_yeji = 0;
        }else{
            $avg_yeji =  round($score_t/$standard_t,4)*100;
        }

        //计算考勤
        $kaoqin_set = AttendanceSet::where('year_param',$year_param)->where('corpid',$perf->corpid)->first();
        $kq_late = Attendance::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('late');
        $kq_early = Attendance::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('early');
        $kq_ab = Attendance::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('absenteeism');
        $kq_business = Attendance::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('business');
        $kq_sick = Attendance::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('sick');
        $kq_jiaban = Attendance::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('overtime');
        $kaoqin_score = $kaoqin_set->late * $kq_late + $kaoqin_set->early * $kq_early + $kaoqin_set->absenteeism * $kq_ab + $kaoqin_set->business * $kq_business + $kaoqin_set->sick * $kq_sick + $kaoqin_set->overtime * $kq_jiaban;

        //计算奖惩
        $reward_set = RewardPunishSet::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('kind','1')->first();
        $rdetail = RewardPunishSetDetail::where('set_id',$reward_set->id)->lists('set_value','id')->toArray();
        $reward = RewardPunishDetail::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('to_user_id',$perf->user_id)->where('is_effective','1')->where('kind','1')->get();
        $reward_score = 0;
        foreach ($reward as $r){
            if(isset($rdetail[$r->set_detail_id])){
                $sc = $rdetail[$r->set_detail_id];
            }else{
                $sc = 0;
            }
            $reward_score += $sc;
        }

        $punish_set = RewardPunishSet::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('kind','2')->first();
        $pdetail = RewardPunishSetDetail::where('set_id',$punish_set->id)->lists('set_value','id')->toArray();
        $punish = RewardPunishDetail::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('to_user_id',$perf->user_id)->where('is_effective','1')->where('kind','2')->get();
        $punish_score = 0;
        foreach ($punish as $r){
            if(isset($pdetail[$r->set_detail_id])){
                $sc = $pdetail[$r->set_detail_id];
            }else{
                $sc = 0;
            }
            $punish_score += $sc;
        }

        $perf->jiangcheng = $reward_score - $punish_score;
        $perf->kaoqin = $kaoqin_score;
        $perf->yeji = $avg_yeji;
        $perf->total = $avg_yeji + $kaoqin_score+ $reward_score - $punish_score;
        $perf->save();




        //绩效数据月度---考勤，业绩，奖惩总分
        $month_percent = array();
        $year_sales = 0;
        $year_cost = 0;
        $month_title_array = array();
        $month_sales_array = array();
        $month_cost_array = array();
        $month_array = array();
        $change_array = array('01'=>0, '02'=>0, '03'=>0, '04'=>0, '05'=>0, '06'=>0, '07'=>0, '08'=>0, '09'=>0, '10'=>0, '11'=>0, '12'=>0);
        foreach ($change_array as $k=> &$v){
            $month_param = $year_param.$k;
            $month_yeji = 0;
            $standard_t = Achievement::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('standard');
            $score_t = Achievement::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('score');
            $cost_t = AchievementCostDetail::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('score');
            $month_title = AchievementCost::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->first();
            $month_percent_ob = AchievementCostStandard::where('month_param',$month_param)->where('corpid',$perf->corpid)->first();
            if(empty($month_title)){
                $month_title_array[] = null;
            }else{
                $month_title_array[] = $month_title;
            }
            if(empty($month_percent_ob)){
                $month_percent[] = null;
            }else{
                $month_percent[] = $month_percent_ob->percent;
            }
            //20201126
            $month_sales_array[] = $score_t;
            $month_cost_array[] = $cost_t;

            $year_sales += $score_t;
            $year_cost += $cost_t;
            
            if($standard_t == 0){
                $avg_month_yeji = 0;
            }else{
                $avg_month_yeji =  round($score_t/$standard_t,4)*100;
            }


            $kq_late = Attendance::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('late');
            $kq_early = Attendance::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('early');
            $kq_ab = Attendance::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('absenteeism');
            $kq_business = Attendance::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('business');
            $kq_sick = Attendance::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('sick');
            $kq_jiaban = Attendance::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('overtime');
            $kaoqin_score = $kaoqin_set->late * $kq_late + $kaoqin_set->early * $kq_early + $kaoqin_set->absenteeism * $kq_ab + $kaoqin_set->business * $kq_business + $kaoqin_set->sick * $kq_sick + $kaoqin_set->overtime * $kq_jiaban;


            $reward = RewardPunishDetail::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('to_user_id',$perf->user_id)->where('is_effective','1')->where('kind','1')->get();
            $reward_score = 0;
            foreach ($reward as $r){
                if(isset($rdetail[$r->set_detail_id])){
                    $sc = $rdetail[$r->set_detail_id];
                }else{
                    $sc = 0;
                }
                $reward_score += $sc;
            }

            $punish = RewardPunishDetail::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('to_user_id',$perf->user_id)->where('is_effective','1')->where('kind','2')->get();
            $punish_score = 0;
            foreach ($punish as $r){
                if(isset($pdetail[$r->set_detail_id])){
                    $sc = $pdetail[$r->set_detail_id];
                }else{
                    $sc = 0;
                }
                $punish_score += $sc;
            }

            $month_yeji = $avg_month_yeji + $kaoqin_score+ $reward_score - $punish_score;

            $v = $month_yeji;
            $month_array[] = $v;
        }
        $month_array = json_encode($month_array);


        //月度意见
        $opinion = Feedback::where('year_param',$year_param)->where('corpid',$this->corpid)->get();
        $total_people = User::where('corpid', $this->corpid)->where('status', '1')->count();
        $return_opinion_name = array();
        $return_opinion_value = array();
        foreach ($opinion as $op){
            $set = FeedbackSetDetail::where('set_id',$op->id)->lists('set_value','id')->toArray();
            $details = FeedbackDetail::where('year_param',$year_param)->where('corpid',$this->corpid)->where('to_user_id',$uid)->get();
            $op_total = 0;
            $op_time = 0;
            foreach ($details as $d){
                if(isset($set[$d->set_detail_id])){
                    $so = $set[$d->set_detail_id];
                }else{
                    $so = 4;
                }
                $op_total += $so;
                $op_time += 1;
            }
            $total_score = round(($total_people * 4 * 12 + ($op_total - $op_time * 4))/($total_people * 12),2);
            $return_opinion_name[] = $op->name;
            $return_opinion_value[] = $total_score;
        }
        $is_origin = 1;
        //dd($return_opinion_name,$return_opinion_value);
        $return_opinion_value = json_encode($return_opinion_value);



        $ac_id=$uid;
        $tips = Tips::where('corpid', $this->corpid)->with(["Achievement"=>function($query)use($ac_id,$year_param){

            $query->where('user_id', $ac_id)->where('corpid',$this->corpid)->where('year_param',$year_param);
        }])->get();


        $tisNum = [];
        $tisName = [];
        $tisCol = [];
        //  dd($tips);
        foreach ($tips as $k => $tip) {
            $standard = 0;
            $score = 0;
            foreach ($tip->Achievement as $k2 => $tip2) {
                $standard += $tip2->standard;
                $score += $tip2->score;
            }
            if ($score == 0) {
                $tisNum[$k] = 0;
            } else {
                // dd($standard);
                $tisNum[$k] = intval($score / $standard * 100);
            }
            $tisName[$k] = substr($tip->name , 0 , 18);
            $tisCol[$k]= $tip->color;

        }
        $is_admin = 0;
        $role = RoleUser::where('corpid', $this->corpid)->where('user_id', $this->user->id)->where('role_id', '9')->first();
        if (!empty($role)) {
            $is_admin = 1;
        }
        //dd($tisNum);

        //20201207权限
        if($this->getAccess($uid) == 1){
            $has_access = 1;
        }else{
            $has_access = 0;
        }

        $view = 'frontuser.history-evaluation';
        return view($view)
            ->with('has_access', $has_access)
            ->with('month_percent', $month_percent)
            ->with('year_sales', $year_sales)
            ->with('year_cost', $year_cost)
            ->with('month_title_array', $month_title_array)
            ->with('month_sales_array', $month_sales_array)
            ->with('month_cost_array', $month_cost_array)
            ->with('months', $month_array)
            ->with('value_opinion', $return_opinion_value)
            ->with('name_opinion', $return_opinion_name)
            ->with('myuid', $this->user->id)
            ->with('uid', $uid)
            ->with('user', $user_logo)
            ->with('is_origin', $is_origin)
            ->with('perf', $perf)
            ->with('is_admin', $is_admin)
            ->with('year_param', $year_param)
            ->with('yearlist', $yearlist)
            ->with('tisNum', json_encode($tisNum))
            ->with('tisCol', json_encode($tisCol))
            ->with('tisName', json_encode($tisName))
            ->with('tips', $tips);
    }
    
    
    
    //我的考评
    public function getPerf(Request $request)
    {
        $uid = $request->input('uid', 0);
        if ($uid <= 0) {
            $uid = $this->user->id;
        }
        $user_logo = User::find($uid);
        $year_param = $request->input('year', 0);
        $company = Company::where('id',$this->corpid)->first();
        if(!is_positive_int($year_param)){
            $year_param = getCurrentYear();
        }
        if(!in_array($year_param,explode(',',$company->years_array))){
            $year_param = $company->from_year;
        }

        $perf = UserPerformance::where('user_id',$uid)->where('corpid',$this->corpid)->where('year_param',$year_param)->first();
        if(empty($perf)){
            $perf = new UserPerformance();
            $perf->corpid = $this->corpid;
            $perf->year_param = $year_param;
            $perf->user_id = $uid;
            $perf->save();
        }

        $standard_t = Achievement::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('standard');
        $score_t = Achievement::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('score');
        if($standard_t == 0){
            $avg_yeji = 0;
        }else{
            $avg_yeji =  round($score_t/$standard_t,4)*100;
        }

        //计算考勤
        $kaoqin_set = AttendanceSet::where('year_param',$year_param)->where('corpid',$perf->corpid)->first();
        $kq_late = Attendance::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('late');
        $kq_early = Attendance::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('early');
        $kq_ab = Attendance::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('absenteeism');
        $kq_business = Attendance::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('business');
        $kq_sick = Attendance::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('sick');
        $kq_jiaban = Attendance::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('overtime');
        $kaoqin_score = $kaoqin_set->late * $kq_late + $kaoqin_set->early * $kq_early + $kaoqin_set->absenteeism * $kq_ab + $kaoqin_set->business * $kq_business + $kaoqin_set->sick * $kq_sick + $kaoqin_set->overtime * $kq_jiaban;

        //计算奖惩
        $reward_set = RewardPunishSet::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('kind','1')->first();
        $rdetail = RewardPunishSetDetail::where('set_id',$reward_set->id)->lists('set_value','id')->toArray();
        $reward = RewardPunishDetail::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('to_user_id',$perf->user_id)->where('is_effective','1')->where('kind','1')->get();
        $reward_score = 0;
        foreach ($reward as $r){
            if(isset($rdetail[$r->set_detail_id])){
                $sc = $rdetail[$r->set_detail_id];
            }else{
                $sc = 0;
            }
            $reward_score += $sc;
        }

        $punish_set = RewardPunishSet::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('kind','2')->first();
        $pdetail = RewardPunishSetDetail::where('set_id',$punish_set->id)->lists('set_value','id')->toArray();
        $punish = RewardPunishDetail::where('year_param',$year_param)->where('corpid',$perf->corpid)->where('to_user_id',$perf->user_id)->where('is_effective','1')->where('kind','2')->get();
        $punish_score = 0;
        foreach ($punish as $r){
            if(isset($pdetail[$r->set_detail_id])){
                $sc = $pdetail[$r->set_detail_id];
            }else{
                $sc = 0;
            }
            $punish_score += $sc;
        }

        $perf->jiangcheng = $reward_score - $punish_score;
        $perf->kaoqin = $kaoqin_score;
        $perf->yeji = $avg_yeji;
        $perf->total = $avg_yeji + $kaoqin_score+ $reward_score - $punish_score;
        $perf->save();




        //绩效数据月度---考勤，业绩，奖惩总分
        $month_percent = array();
        $year_sales = 0;
        $year_cost = 0;
        $month_title_array = array();
        $month_sales_array = array();
        $month_cost_array = array();
        $month_array = array();
        $change_array = array('01'=>0, '02'=>0, '03'=>0, '04'=>0, '05'=>0, '06'=>0, '07'=>0, '08'=>0, '09'=>0, '10'=>0, '11'=>0, '12'=>0);
        foreach ($change_array as $k=> &$v){
            $month_param = $year_param.$k;
            $month_yeji = 0;
            $standard_t = Achievement::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('standard');
            $score_t = Achievement::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('score');
            $cost_t = AchievementCostDetail::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('score');
            $month_title = AchievementCost::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->first();
            $month_percent_ob = AchievementCostStandard::where('month_param',$month_param)->where('corpid',$perf->corpid)->first();
            if(empty($month_title)){
                $month_title_array[] = null;
            }else{
                $month_title_array[] = $month_title;
            }
            if(empty($month_percent_ob)){
                $month_percent[] = null;
            }else{
                $month_percent[] = $month_percent_ob->percent;
            }
            //20201126
            $month_sales_array[] = $score_t;
            $month_cost_array[] = $cost_t;

            $year_sales += $score_t;
            $year_cost += $cost_t;

            if($standard_t == 0){
                $avg_month_yeji = 0;
            }else{
                $avg_month_yeji =  round($score_t/$standard_t,4)*100;
            }


            $kq_late = Attendance::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('late');
            $kq_early = Attendance::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('early');
            $kq_ab = Attendance::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('absenteeism');
            $kq_business = Attendance::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('business');
            $kq_sick = Attendance::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('sick');
            $kq_jiaban = Attendance::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('user_id',$perf->user_id)->sum('overtime');
            $kaoqin_score = $kaoqin_set->late * $kq_late + $kaoqin_set->early * $kq_early + $kaoqin_set->absenteeism * $kq_ab + $kaoqin_set->business * $kq_business + $kaoqin_set->sick * $kq_sick + $kaoqin_set->overtime * $kq_jiaban;


            $reward = RewardPunishDetail::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('to_user_id',$perf->user_id)->where('is_effective','1')->where('kind','1')->get();
            $reward_score = 0;
            foreach ($reward as $r){
                if(isset($rdetail[$r->set_detail_id])){
                    $sc = $rdetail[$r->set_detail_id];
                }else{
                    $sc = 0;
                }
                $reward_score += $sc;
            }

            $punish = RewardPunishDetail::where('month_param',$month_param)->where('corpid',$perf->corpid)->where('to_user_id',$perf->user_id)->where('is_effective','1')->where('kind','2')->get();
            $punish_score = 0;
            foreach ($punish as $r){
                if(isset($pdetail[$r->set_detail_id])){
                    $sc = $pdetail[$r->set_detail_id];
                }else{
                    $sc = 0;
                }
                $punish_score += $sc;
            }

            $month_yeji = $avg_month_yeji + $kaoqin_score+ $reward_score - $punish_score;

            $v = $month_yeji;
            $month_array[] = $v;
        }
        $month_array = json_encode($month_array);


        //月度意见
        $opinion = Feedback::where('year_param',$year_param)->where('corpid',$this->corpid)->get();
        $total_people = User::where('corpid', $this->corpid)->where('status', '1')->count();
        $return_opinion_name = array();
        $return_opinion_value = array();
        foreach ($opinion as $op){
            $set = FeedbackSetDetail::where('set_id',$op->id)->lists('set_value','id')->toArray();
            $details = FeedbackDetail::where('year_param',$year_param)->where('corpid',$this->corpid)->where('to_user_id',$uid)->get();
            $op_total = 0;
            $op_time = 0;
            foreach ($details as $d){
                if(isset($set[$d->set_detail_id])){
                    $so = $set[$d->set_detail_id];
                }else{
                    $so = 4;
                }
                $op_total += $so;
                $op_time += 1;
            }
            $total_score = round(($total_people * 4 * 12 + ($op_total - $op_time * 4))/($total_people * 12),2);
            $return_opinion_name[] = $op->name;
            $return_opinion_value[] = $total_score;
        }
        $is_origin = 1;
        //dd($return_opinion_name,$return_opinion_value);
        $return_opinion_value = json_encode($return_opinion_value);



        $ac_id=$uid;
        $tips = Tips::where('corpid', $this->corpid)->with(["Achievement"=>function($query)use($ac_id,$year_param){

            $query->where('user_id', $ac_id)->where('year_param',$year_param);
        }])->get();


        $tisNum = [];
        $tisName = [];
        $tisCol = [];
      //  dd($tips);
        foreach ($tips as $k => $tip) {
            $standard = 0;
            $score = 0;
            foreach ($tip->Achievement as $k2 => $tip2) {
                $standard += $tip2->standard;
                $score += $tip2->score;
            }
            if ($score == 0) {
                $tisNum[$k] = 0;
            } else {
               // dd($standard);
                $tisNum[$k] = intval($score / $standard * 100);
            }
            $tisName[$k] = substr($tip->name , 0 , 18);
            $tisCol[$k]= $tip->color;

        }
        //dd($tisNum);
        $is_admin = 0;
        $role = RoleUser::where('corpid', $this->corpid)->where('user_id', $this->user->id)->where('role_id', '9')->first();
        if (!empty($role)) {
            $is_admin = 1;
        }

        //20201126新增销售费用
        //dd($month_sales_array,$month_cost_array,$month_title_array);

        //20201207权限
        if($this->getAccess($uid) == 1){
            $has_access = 1;
        }else{
            $has_access = 0;
        }



        $view = 'frontuser.my-evaluation';
        return view($view)
            ->with('has_access', $has_access)
            ->with('month_percent', $month_percent)
            ->with('year_sales', $year_sales)
            ->with('year_cost', $year_cost)
            ->with('month_title_array', $month_title_array)
            ->with('month_sales_array', $month_sales_array)
            ->with('month_cost_array', $month_cost_array)
            ->with('months', $month_array)
            ->with('value_opinion', $return_opinion_value)
            ->with('name_opinion', $return_opinion_name)
            ->with('myuid', $this->user->id)
            ->with('uid', $uid)
            ->with('user', $user_logo)
            ->with('is_origin', $is_origin)
            ->with('perf', $perf)
            ->with('is_admin', $is_admin)
            ->with('year_param', $year_param)
            ->with('tisNum', json_encode($tisNum))
            ->with('tisCol', json_encode($tisCol))
            ->with('tisName', json_encode($tisName))
            ->with('tips', $tips);
    }


    private function transferAccount($money)
    {
        $is_minus = 0;
        if($money < 0){
            $money = $money/-1;
            $is_minus = 1;
        }
        if($money/100000000 > 1){
            $money = round($money/100000000,2);
            if($is_minus = 1){
                return $money/-1;
            }else{
                return $money;
            }
        }
        if($money/1000000 > 1){
            $money = round($money/10000,2);
            if($is_minus = 1){
                return $money/-1;
            }else{
                return $money;
            }
        }
        return $money;

    }


    //全员考评
    public function getAllPerf(Request $request)
    {
        $year_param = $request->input('year', 0);
        $company = Company::where('id',$this->corpid)->first();
        if(!is_positive_int($year_param)){
            $year_param = getCurrentYear();
        }
        if(!in_array($year_param,explode(',',$company->years_array))){
            $year_param = $company->from_year;
        }

        $years = explode(',',$company->years_array);
        rsort($years);
        $now = date('Y') + 10;
        $yearlist = array();
        foreach($years as $y){
            $yearlist[] = array(
                'id'=>$y,
                'value'=>$y.'年',
            );
        }
        $yearlist = json_encode($yearlist);
        
        
        $uu = User::where('corpid',$this->corpid)->where('status','1')->orderBy('is_leader','desc')->orderByRaw('CONVERT (kh_users.qw_name USING gbk)')->get();
        if(count($uu) > 0){
            foreach ($uu as $u){
                $perf = UserPerformance::where('user_id',$u->id)->where('corpid',$this->corpid)->where('year_param',$year_param)->first();
                if(!empty($perf)){
                    $standard_t = Achievement::where('year_param',$year_param)->where('corpid',$this->corpid)->where('user_id',$u->id)->sum('standard');
                    $score_t = Achievement::where('year_param',$year_param)->where('corpid',$this->corpid)->where('user_id',$u->id)->sum('score');
                    if($standard_t == 0){
                        $avg_yeji = 0;
                    }else{
                        $avg_yeji =  round($score_t/$standard_t,4)*100;
                    }

                    //计算考勤
                    $kaoqin_set = AttendanceSet::where('year_param',$year_param)->where('corpid',$this->corpid)->first();
                    $kq_late = Attendance::where('year_param',$year_param)->where('corpid',$this->corpid)->where('user_id',$u->id)->sum('late');
                    $kq_early = Attendance::where('year_param',$year_param)->where('corpid',$this->corpid)->where('user_id',$u->id)->sum('early');
                    $kq_ab = Attendance::where('year_param',$year_param)->where('corpid',$this->corpid)->where('user_id',$u->id)->sum('absenteeism');
                    $kq_business = Attendance::where('year_param',$year_param)->where('corpid',$this->corpid)->where('user_id',$u->id)->sum('business');
                    $kq_sick = Attendance::where('year_param',$year_param)->where('corpid',$this->corpid)->where('user_id',$u->id)->sum('sick');
                    $kq_jiaban = Attendance::where('year_param',$year_param)->where('corpid',$this->corpid)->where('user_id',$u->id)->sum('overtime');
                    $kaoqin_score = $kaoqin_set->late * $kq_late + $kaoqin_set->early * $kq_early + $kaoqin_set->absenteeism * $kq_ab + $kaoqin_set->business * $kq_business + $kaoqin_set->sick * $kq_sick + $kaoqin_set->overtime * $kq_jiaban;
                    $kaoqin_score = round($kaoqin_score,2);

                    //计算奖惩
                    $reward_set = RewardPunishSet::where('year_param',$year_param)->where('corpid',$this->corpid)->where('kind','1')->first();
                    $rdetail = RewardPunishSetDetail::where('set_id',$reward_set->id)->lists('set_value','id')->toArray();
                    $reward = RewardPunishDetail::where('year_param',$year_param)->where('corpid',$this->corpid)->where('to_user_id',$u->id)->where('is_effective','1')->where('kind','1')->get();
                    $reward_score = 0;
                    foreach ($reward as $r){
                        if(isset($rdetail[$r->set_detail_id])){
                            $sc = $rdetail[$r->set_detail_id];
                        }else{
                            $sc = 0;
                        }
                        $reward_score += $sc;
                    }

                    $punish_set = RewardPunishSet::where('year_param',$year_param)->where('corpid',$this->corpid)->where('kind','2')->first();
                    $pdetail = RewardPunishSetDetail::where('set_id',$punish_set->id)->lists('set_value','id')->toArray();
                    $punish = RewardPunishDetail::where('year_param',$year_param)->where('corpid',$this->corpid)->where('to_user_id',$u->id)->where('is_effective','1')->where('kind','2')->get();
                    $punish_score = 0;
                    foreach ($punish as $r){
                        if(isset($pdetail[$r->set_detail_id])){
                            $sc = $pdetail[$r->set_detail_id];
                        }else{
                            $sc = 0;
                        }
                        $punish_score += $sc;
                    }

                    $perf->jiangcheng = $reward_score - $punish_score;
                    $perf->kaoqin = $kaoqin_score;
                    $perf->yeji = $avg_yeji;
                    $perf->total = $avg_yeji + $kaoqin_score+ $reward_score - $punish_score;
                    $perf->save();
                }

            }
        }
        
        $groups = Group::where('corpid', $this->corpid)->get();
        if($groups->count() <= 0){
            abort(405,'目前系统没有分组，'.'请先新建分组');
        }
        foreach ($groups as $gt) {
            $gt->users = User::where('group_id', $gt->id)->where('status', '1')->orderBy('is_leader','desc')->orderByRaw('CONVERT (kh_users.qw_name USING gbk)')->get();
        }
        $g_collect = collect();
        foreach ($groups as $g) {
            if ($g->fid == 0) {
                $g_collect[] = $g;
                foreach ($groups as $gg) {
                    if ($gg->fid == $g->id) {
                        $g_collect[] = $gg;
                        foreach ($groups as $ggg) {
                            if ($ggg->fid == $gg->id) {
                                $g_collect[] = $ggg;
                            }
                        }
                    }
                }
            }
        }
        //$perf = UserPerformance::where('corpid',$this->corpid)->get();
        $is_admin = 0;
        $role = RoleUser::where('corpid', $this->corpid)->where('user_id', $this->user->id)->where('role_id', '9')->first();
        if (!empty($role)) {
            $is_admin = 1;
        }
        $view = 'frontuser.all-evaluation';
        return view($view)
            ->with('year_param', $year_param)
            ->with('is_admin', $is_admin)
            ->with('year_param', $year_param)
            ->with('yearlist', $yearlist)
            ->with('perf', $g_collect);
    }


    private function getAccess($uid)
    {
        $self = $this->user;
        if($self->id == $uid){
            return 1;
        }
        $role = $this->user->getRole();
        if($role==9){
            return 1;
        }else{
            if($role == 11){
                $scope=unserialize(RoleUser::where('user_id',$this->user->id)->where("role_id",11)->first()->scope);
                if(in_array($uid,$scope)){
                    return 1;
                }
            }
        }
        $perfuser = User::find($uid);
        if(!empty($perfuser)){
            $group_array = array();
            $group = Group::find($perfuser->group_id);
            $group_array[] = $group->id;
            while($group->fid != 0){
                $topgroup = Group::find($group->fid);
                $group_array[] = $topgroup->id;
                $group = $topgroup;
            }
            if(in_array($self->group_id,$group_array) && $self->is_leader == 1){
                return 1;
            }
        }
        return 0;

    }


    public function getIndex(Request $request)
    {
        return redirect('/wxstart');
        /*$suiteid = 'wwa27e2080fe46150f';
        $redirect_uri = urlencode('kaohe.cimo.cn/user/performance/userinfo');
        $url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$suiteid.'&redirect_uri='.$redirect_uri.'&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect';
        return redirect($url);*/
    }

    public function tig(Request $request)
    {
        $name = $request->name;
        $uid = $request->input('uid');
        if (!$uid){
            abort(404);
        }
        $tips = Tips::where("name", $name)->with('Achievement')->with(["Achievement"=>function($query)use($uid ){
            $query->where('user_id', $uid );
        }])->first();
        $tips=$tips->Achievement;
        $res=[];
        foreach ($tips as $k=>$v){
            $res[$v->created_at->year][$k]=$v;
        }
        //dd($res);
        return view("frontuser.list-detail")->with('tips',$res)->with('name',$name);


    }

    public function getUserinfo(Request $request)
    {
        //session_start(); // 初始化session
        $suiteid = 'wwa27e2080fe46150f';
        $secret = 'iQkzSQD9RgLVsMRBUoua6w1rFc7RWoweF5ja_8QYAPY';
        $code = $request->input('code');
        $key = Keys::where('name', 'kh_suite_ticket')->orderBy('id', 'desc')->first()->value;
        $uri = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_suite_token';
        $curl = new Curl();
        $data = array(
            'suite_id' => $suiteid,
            'suite_secret' => $secret,
            'suite_ticket' => $key,
        );
        $data = json_encode($data);
        $curl->post($uri, $data);
        $suite_access_token = $curl->response->suite_access_token;
        $curl->close();

        /*//预授权码
        $url_pre_auth_code = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_pre_auth_code?suite_access_token='.$suite_access_token;
        $return_json_pre = json_decode(file_get_contents($url_pre_auth_code));
        $pre_auth_code = $return_json_pre->pre_auth_code;
        //dd($pre_auth_code);*/


        /*//获取企业永久授权码
        $url_permanent_code = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_permanent_code?suite_access_token='.$suite_access_token;
        $curl_permanent_code  =  new Curl();
        $data_permanent_code = array(
            'auth_code'    => $code,
        );
        $data_permanent_code = json_encode($data_permanent_code);
        $curl_permanent_code->post($url_permanent_code,$data_permanent_code);
        $curl_permanent_code->close();
        dd($curl_permanent_code);
        $auth_corpid = $curl_permanent_code->auth_corp_info->corpid;//授权企业id

        $permanent_code = $curl_permanent_code->permanent_code;//授权企业永久码*/

        $url = 'https://qyapi.weixin.qq.com/cgi-bin/service/getuserinfo3rd?access_token=' . $suite_access_token . '&code=' . $code;
        $return_json = json_decode(file_get_contents($url));
        $user_ticket = $return_json->user_ticket;
        $auth_corpid = $return_json->CorpId;


        /*$uri = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_auth_info?suite_access_token='.$suite_access_token;
        $curl  =  new Curl();
        $data = array(
            'auth_corpid'    => $corpid,
            'permanent_code'    => $p_code,
        );
        $data = json_encode($data);
        $curl->post($uri,$data);
        $agentid = $curl->response->auth_info->agent[0]->agentid;
        $curl->close();*/
        //dd($agentid);
        /*//企业管理员列表
        $url_admin_list = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_admin_list?suite_access_token='.$suite_access_token;
        $curl_admin_list  =  new Curl();
        $data_admin_list = array(
            'auth_corpid'    => $auth_corpid,
            'agentid'    => $agentid,
        );
        $data_admin_list = json_encode($data_admin_list);
        $curl_admin_list->post($url_admin_list,$data_admin_list);
        $curl_admin_list->close();
        $admin_list = $curl_admin_list->response->admin;//管理员列表json数组
        var_dump($admin_list);*/


        $corpinfo = CorpInfo::where('corpid', $auth_corpid)->orderBy('id', 'desc')->first();
        $auth_userid = $corpinfo->auth_userid;


        $detail_uri = 'https://qyapi.weixin.qq.com/cgi-bin/service/getuserdetail3rd?access_token=' . $suite_access_token;
        $curl2 = new Curl();
        $data2 = array(
            'user_ticket' => $user_ticket,
        );
        $data2 = json_encode($data2);
        $curl2->post($detail_uri, $data2);
        $curl2->close();
        $userid = $curl2->response->userid;
        $username = $curl2->response->name;
        $gender = $curl2->response->gender;

        $user_exist = User::where('corpid', $auth_corpid)->where('qw_userid', $userid)->first();
        if (empty($user_exist)) {
            $new = new User();
            $new->corpid = $auth_corpid;
            $new->qw_userid = $userid;
            $new->qw_name = $username;
            $new->gender = $gender;
            $new->save();

            Auth::login($new);

            //用户为授权管理员，赋予系统管理员权限
            if ($auth_userid == $userid) {
                $role = new RoleUser();
                $role->corpid = $auth_corpid;
                $role->user_id = $new->id;
                $role->role_id = '9';
                $role->save();
            }

        } else {
            Auth::login($user_exist);
        }

        return;
    }


    //个人绩效总分页-图表等
    //访问地址  /user/performance/user-total
    public function getUserTotal()
    {
        $result = UserPerformance::first();
        $users = User::find(6);
        $year = array(
            1 => '50',
            2 => '60',
            3 => '80',
            4 => '70',
            5 => '70',
            6 => '90',
            7 => '84',
            8 => '77',
            9 => '66',
            10 => '82',
            11 => '85',
            12 => '88',
        );
        // $year = json_encode($year);
        $yijian = array(
            '主动性' => '4.5',
            '能动性' => '4.2',
            '观赏性' => '3.8',
            '合作性' => '5.0',
            '敬业性' => '4.8',
        );
        dd($yijian, $year);
        $yijian = json_encode($yijian);
        $view = 'user.kaohe.all-review';
        return view($view)
            ->with('yijian', $yijian)
            ->with('year', $year)
            ->with('result', $result)
            ->with('user', $users);
    }

    //全员考评
    //访问地址  /user/performance/alluser
    public function getAlluser()
    {
        $users = User::find(6);
        $user1 = array(
            'userid' => '1',
            'name' => '张三',
            'score' => '60',
        );
        $user2 = array(
            'userid' => '2',
            'name' => '用户2',
            'score' => '80',
        );
        $user3 = array(
            'userid' => '3',
            'name' => '李四',
            'score' => '102',
        );
        $user4 = array(
            'userid' => '4',
            'name' => '王五',
            'score' => '55',
        );
        $user5 = array(
            'userid' => '5',
            'name' => '胡八',
            'score' => '94',
        );
        $part3 = array(
            'groupid' => '3',
            'name' => '三级部门',
            'member' => array($user5, $user4),
            'child' => array(),
        );
        $part2 = array(
            'groupid' => '2',
            'name' => '二级部门',
            'member' => array($user2, $user3),
            'child' => array($part3),
        );

        $tongxunlu = array(
            'groupid' => '1',
            'name' => '一级部门',
            'member' => array($user1),
            'child' => array($part2),
        );
        //dd($tongxunlu);
        dd($tongxunlu);
        $year = json_encode($tongxunlu);

        $view = 'user.kaohe.all-access';
        return view($view)
            ->with('user', $users)
            ->with('year', $year);
    }

    //月度意见
    //访问地址  /user/performance/yuedu
    public function getYuedu()
    {
        $users = User::find(6);
        $user1 = array(
            'userid' => '1',
            'name' => '张三',
            'score' => '60',
        );
        $user2 = array(
            'userid' => '2',
            'name' => '用户2',
            'score' => '80',
        );
        $user3 = array(
            'userid' => '3',
            'name' => '李四',
            'score' => '102',
        );
        $user4 = array(
            'userid' => '4',
            'name' => '王五',
            'score' => '55',
        );
        $user5 = array(
            'userid' => '5',
            'name' => '胡八',
            'score' => '94',
        );
        $part3 = array(
            'groupid' => '3',
            'name' => '三级部门',
            'member' => array($user5, $user4),
            'child' => array(),
        );
        $part2 = array(
            'groupid' => '2',
            'name' => '二级部门',
            'member' => array($user2, $user3),
            'child' => array($part3),
        );

        $tongxunlu = array(
            'groupid' => '1',
            'name' => '一级部门',
            'member' => array($user1),
            'child' => array($part2),
        );
        //dd($tongxunlu);
        $yuedu = array(
            '主动性' => array(
                '很差' => '-5',
                '较差' => '-3',
                '正常' => '0',
                '较好' => '3',
                '很好' => '5',
            ),
            '学习能力' => array(
                '很差' => '-5',
                '较差' => '-3',
                '正常' => '0',
                '较好' => '3',
                '很好' => '5',
            ),
            '合作精神' => array(
                '很差' => '-5',
                '较差' => '-3',
                '正常' => '0',
                '较好' => '3',
                '很好' => '5',
            ),
            '敬业精神' => array(
                '很差' => '-5',
                '较差' => '-3',
                '正常' => '0',
                '较好' => '3',
                '很好' => '5',
            ),
            '专业技能' => array(
                '很差' => '-5',
                '较差' => '-3',
                '正常' => '0',
                '较好' => '3',
                '很好' => '5',
            ),
        );
        dd($yuedu, $tongxunlu);
        $yuedu = json_encode($yuedu);
        $year = json_encode($tongxunlu);
        //dd($year);
        $view = 'user.kaohe.yuedu';
        return view($view)
            ->with('user', $users)
            ->with('yuedu', $yuedu)
            ->with('year', $year);
    }

    //考勤详细
    //访问地址  /user/performance/kaoqin
    public function getKaoqin()
    {
        $users = User::find(6);

        $detail = array(
            '2018-09-01' => array(
                'queqin' => 1,
                'gongjia' => 0,
                'jiaban' => 1,
                'message' => '缺勤：事假0.5天；迟到1分钟. 加班：1小时',
                'note' => '加急完成海报工作',
            ),
            '2018-09-12' => array(
                'queqin' => 0,
                'gongjia' => 1,
                'jiaban' => 0,
                'message' => '缺勤：事假0.5天；迟到1分钟. 加班：1小时',
                'note' => '加急完成海报工作',
            ),
            '2018-09-30' => array(
                'queqin' => 0,
                'gongjia' => 0,
                'jiaban' => 1,
                'message' => '缺勤：事假0.5天；迟到1分钟. 加班：1小时',
                'note' => '加急完成海报工作',
            ),
        );
        //$detail = json_encode($detail);
        dd($detail);
        $view = 'user.kaohe.kaoqin';
        return view($view)
            ->with('user', $users)
            ->with('detail', $detail);
    }

    //业绩详细
    //访问地址  /user/performance/yeji
    public function getYeji()
    {
        $users = User::find(6);

        $detail = array(
            '2018-08' => array(
                'target' => 100,
                'percent' => '80%',
                'note' => '销售额完成情况',
            ),
        );
        //$detail = json_encode($detail);
        dd($detail);
        $view = 'user.kaohe.yeji';
        return view($view)
            ->with('user', $users)
            ->with('detail', $detail);
    }

    //我收到的奖惩
    //访问地址  /user/performance/jiangcheng
    public function getJiangcheng()
    {
        $users = User::find(6);

        $jiangli = array(
            array(
                'from' => '网银',
                'to' => '我',
                'class' => '低级',
                'score' => 1,
                'reason' => '理解能力差，沟通困难',
                'date' => '2018-08-06',
            ),
            array(
                'from' => '网银',
                'to' => '我',
                'class' => '低级',
                'score' => 1,
                'reason' => '理解能力差，沟通困难',
                'date' => '2018-08-07',
            ),
            array(
                'from' => '网银',
                'to' => '我',
                'class' => '高级',
                'score' => 3,
                'reason' => '理解能力差，沟通困难',
                'date' => '2018-08-09',
            ),
        );

        $chengfa = array(
            array(
                'from' => '王莹',
                'to' => '我',
                'class' => '低级',
                'score' => 1,
                'reason' => '理解能力赞',
                'date' => '2018-08-06',
            ),
            array(
                'from' => '网银',
                'to' => '我',
                'class' => '低级',
                'score' => 1,
                'reason' => '理解能力赞',
                'date' => '2018-08-07',
            ),
            array(
                'from' => '网银',
                'to' => '我',
                'class' => '高级',
                'score' => 3,
                'reason' => '理解能力赞',
                'date' => '2018-08-09',
            ),
        );
        //$detail = json_encode($detail);
        dd($jiangli, $chengfa);
        $jiangli = json_encode($jiangli);
        $chengfa = json_encode($chengfa);
        //dd($detail);
        $view = 'user.kaohe.kaoqin';
        return view($view)
            ->with('user', $users)
            ->with('jiangli', $jiangli)
            ->with('chengfa', $chengfa);
    }

    //我发起的奖惩
    //访问地址  /user/performance/faqi
    public function getFaqi()
    {
        $users = User::find(6);

        $jiangli = array(
            array(
                'from' => '我',
                'to' => '王莹',
                'kind' => '奖励',
                'status' => '已生效',
                'class' => '低级',
                'score' => 1,
                'reason' => '理解能力好',
                'liucheng' => array(
                    '王莹发起了惩罚',
                    '组长王五修改等级为高级',
                    '组长李四修改等级为低级',
                    '奖惩管理员通过了该请求',
                ),
                'date' => '2018-08-06',
            ),
            array(
                'from' => '我',
                'to' => '程颖',
                'kind' => '惩罚',
                'status' => '处理中',
                'class' => '高级',
                'score' => 3,
                'reason' => '理解能力差，沟通困难',
                'liucheng' => array(
                    '王莹发起了惩罚',
                    '组长王五修改等级为高级',
                    '组长李四修改等级为低级',
                    '奖惩管理员通过了该请求',
                ),
                'date' => '2018-08-07',
            ),
            array(
                'from' => '我',
                'to' => '程颖',
                'kind' => '惩罚',
                'status' => '未通过',
                'class' => '高级',
                'score' => 3,
                'reason' => '理解能力差，沟通困难',
                'liucheng' => array(
                    '王莹发起了惩罚',
                    '组长王五修改等级为高级',
                    '组长李四修改等级为低级',
                    '奖惩管理员通过了该请求',
                ),
                'date' => '2018-08-09',
            ),
        );

        //$detail = json_encode($detail);
        dd($jiangli);
        $jiangli = json_encode($jiangli);
        //dd($detail);
        $view = 'user.kaohe.faqi';
        return view($view)
            ->with('user', $users)
            ->with('jiangli', $jiangli);
    }


    //我的通知
    //访问地址  /user/performance/tongzhi
    public function getTongzhi()
    {
        $users = User::find(6);

        $jiangli = array(
            array(
                'kind' => '奖励通知',
                'content' => '收到一条来自王莹的奖励，奖励等级低级',
                'date' => '2018-08-06 12:00:00',
            ),
            array(
                'kind' => '惩罚通知',
                'content' => '收到一条来自王莹的惩罚，惩罚等级低级',
                'date' => '2018-08-06 12:00:00',
            ),
        );


        //$detail = json_encode($detail);
        dd($jiangli);
        $jiangli = json_encode($jiangli);

        //dd($detail);
        $view = 'user.kaohe.tongzhi';
        return view($view)
            ->with('user', $users)
            ->with('jiangli', $jiangli);
    }

    public function getA(Request $request)
    {
        $uid = $request->input('uid', 0);
        if ($uid <= 0) {
            $uid = $this->user->id;
        }
        $year = date("Y", time());
        $current_m = date("m", time());
        $perf = UserPerformance::where('corpid', $this->corpid)->where('user_id', $uid)->first();
        $view = 'frontuser.test-test';
        //绩效数据月度
        $months = UserPerformanceMonth::where('corpid', $this->corpid)->where('user_id', $uid)->where('month', 'like', $year . '%')->get();
        $month_array = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
        $date_array = array('01' => 0, '02' => 1, '03' => 2, '04' => 3, '05' => 4, '06' => 5, '07' => 6, '08' => 7, '09' => 8, '10' => 9, '11' => 10, '12' => 11);
        foreach ($months as $m) {
            $mo = str_replace($year, '', $m->month);
            $index = $date_array[$mo];
            $month_array[$index] = $m->total;
        }
        $month_array[$current_m] = $perf->total;
        $month_array = json_encode($month_array);
        //月度意见
        $opinion = DB::select('select `feedback_id`, avg(`score`) as sc from kh_feedback_detail where corpid = "' . $this->corpid . '" and   to_user_id = ' . $uid . ' Group By feedback_id');
        $fdname = Feedback::where('corpid', $this->corpid)->lists('name', 'id');
        $fdname = $fdname->toArray();
        $return_op = array();
        foreach ($opinion as $op) {
            $return_op[] = array(
                'value' => $op->sc,
                'name' => $fdname[$op->feedback_id],
            );
        }
        $return_op = json_encode($return_op);

        return view($view)
            ->with('months', $month_array)
            ->with('opinion', $return_op)
            ->with('myuid', $this->user->id)
            ->with('perf', $perf);
    }
}


